class Solution {
public:
    int longestOnes(vector<int>& nums, int k) {
        int zero=0,ans=0;
        for(int left=0,right=0;right<nums.size();++right)
        {
            zero+=nums[right]==0?1:0;
            while(left<=right&&zero>k)
                zero-=nums[left++]==0?1:0;
            ans=max(ans,right-left+1);
        }
        return ans;
    }
};